<?php
function getLoginID()
{
	// CONNECT TO DB

	$login_link = mysql_connect("localhost", "ftreeweb", "ftree_web", TRUE)
	  or die("Could not connect in getLoginID: " . mysql_error());
	//print("login_link=$login_link\nlink=$link\n");
	mysql_select_db("ftree", $login_link) or die("Could not select database from getLoginID");
	$loginid = $_SERVER['REMOTE_USER'];
	//print("loginid=$loginid\n");
	$query = "SELECT * FROM `logins` WHERE `userid` = '$loginid'";
	$result = mysql_query($query, $login_link) or die("Query failed in getLoginID: " . mysql_error());
	$data = mysql_fetch_array($result, MYSQL_ASSOC);
	$id = $data['treeid'];
	//print("new_id=$id\n");
	if ($id == "") { $id = 3054; }  //when in doubt, go to my card
	mysql_free_result($result);
	$id=preg_replace("/[^0-9]/","",$id);  //get rid of anything but numbers
	if ($id < 1 || $id > pow(2,17)) {   
	  $id = 3054; //once again, when in doubt, go to my page
	}                                   
	mysql_close($login_link);
	//print("final_id=$id\n");
	return $id;
}
?>
